home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / h / ast.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-14  |  3.5 KB  |  123 lines  |  [TEXT/MPS ]

  1. /* Abstract syntax tree
  2.  *
  3.  * Macros, definitions
  4.  *
  5.  * SOFTWARE RIGHTS
  6.  *
  7.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  8.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  9.  * company may do whatever they wish with source code distributed with
  10.  * PCCTS or the code generated by PCCTS, including the incorporation of
  11.  * PCCTS, or its output, into commerical software.
  12.  * 
  13.  * We encourage users to develop software with PCCTS.  However, we do ask
  14.  * that credit is given to us for developing PCCTS.  By "credit",
  15.  * we mean that if you incorporate our source code into one of your
  16.  * programs (commercial product, research project, or otherwise) that you
  17.  * acknowledge this fact somewhere in the documentation, research report,
  18.  * etc...  If you like PCCTS and have developed a nice tool with the
  19.  * output, please mention that you developed it using PCCTS.  In
  20.  * addition, we ask that this header remain intact in our source code.
  21.  * As long as these guidelines are kept, we expect to continue enhancing
  22.  * this system and expect to make other tools available as they are
  23.  * completed.
  24.  *
  25.  * ANTLR 1.23
  26.  * Terence Parr
  27.  * Parr Research Corporation
  28.  * with Purdue University and AHPCRC, University of Minnesota
  29.  * 1989-1994
  30.  */
  31.  
  32. #ifndef ZZAST_H
  33. #define ZZAST_H
  34.  
  35. #define zzastOvfChk                                                        \
  36.             if ( zzast_sp <= 0 )                                        \
  37.             {                                                           \
  38.                 fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__);        \
  39.                 exit(-1);                                               \
  40.             }
  41.  
  42. #ifndef USER_DEFINED_AST
  43. #ifndef AST_FIELDS
  44. #define AST_FIELDS
  45. #endif
  46.  
  47. typedef struct _ast {
  48. #ifdef SORCERER_TRANSFORM
  49.             struct _ast *right[2], *down[2];
  50. #ifdef zzAST_DOUBLE
  51.             struct _ast *left[2], *up[2];
  52. #endif
  53. #else
  54.             struct _ast *right, *down;
  55. #ifdef zzAST_DOUBLE
  56.             struct _ast *left, *up;
  57. #endif
  58. #endif
  59.             AST_FIELDS
  60. } AST;
  61.  
  62. #else
  63.  
  64. #ifdef zzAST_DOUBLE
  65. #define AST_REQUIRED_FIELDS   struct _ast *right, *down, *left, *up;
  66. #else
  67. #define AST_REQUIRED_FIELDS   struct _ast *right, *down;
  68. #endif
  69.  
  70. #endif
  71.  
  72.  
  73. /* N o d e  a c c e s s  m a c r o s */
  74. #define zzchild(t)        (((t)==NULL)?NULL:(t->down))
  75. #define zzsibling(t)    (((t)==NULL)?NULL:(t->right))
  76.  
  77.  
  78. /* define global variables needed by #i stack */
  79. #define zzASTgvars                                                \
  80.     AST *zzastStack[ZZAST_STACKSIZE];                            \
  81.     int zzast_sp = ZZAST_STACKSIZE;
  82.  
  83. #define zzASTVars    AST *_ast = NULL, *_sibling = NULL, *_tail = NULL
  84. #define zzSTR        ( (_tail==NULL)?(&_sibling):(&(_tail->right)) )
  85. #define zzastCur    (zzastStack[zzast_sp])
  86. #define zzastArg(i)    (zzastStack[zztsp-i])
  87. #define zzastPush(p) zzastOvfChk; zzastStack[--zzast_sp] = p;
  88. #define zzastDPush    --zzast_sp
  89. #define zzastMARK    zztsp=zzast_sp;        /* Save state of stack */
  90. #define zzastREL    zzast_sp=zztsp;        /* Return state of stack */
  91. #define zzrm_ast    {zzfree_ast(*_root); _tail = _sibling = (*_root)=NULL;}
  92.  
  93. extern int zzast_sp;
  94. extern AST *zzastStack[];
  95.  
  96. #ifdef __STDC__
  97. void zzlink(AST **, AST **, AST **);
  98. void zzsubchild(AST **, AST **, AST **);
  99. void zzsubroot(AST **, AST **, AST **);
  100. void zzpre_ast(AST *, void (*)(), void (*)(), void (*)());
  101. void zzfree_ast(AST *);
  102. AST *zztmake(AST *, ...);
  103. AST *zzdup_ast(AST *);
  104. void zztfree(AST *);
  105. void zzdouble_link(AST *, AST *, AST *);
  106. AST *zzastnew(void);
  107.  
  108. #else
  109.  
  110. void zzlink();
  111. AST *zzastnew();
  112. void zzsubchild();
  113. void zzsubroot();
  114. void zzpre_ast();
  115. void zzfree_ast();
  116. AST *zztmake();
  117. AST *zzdup_ast();
  118. void zztfree();
  119. void zzdouble_link();
  120. #endif
  121.  
  122. #endif
  123.